package com.guan.ordering_sys.generator.controller;


import com.baomidou.mybatisplus.extension.api.R;
import com.guan.ordering_sys.common.ResultApi;
import com.guan.ordering_sys.common.StateCode;
import com.guan.ordering_sys.generator.service.impl.AccountServiceImpl;
import com.guan.ordering_sys.param.AccountParam;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 前端控制器
 *  前端控制器
 * </p>
 *
 * @author 林煜岚
 * @since 2021-06-23
 */
@Api(tags = "用户接口")
@RestController
@RequestMapping("/api/account")
public class AccountController {
    @Autowired
    AccountServiceImpl accountService;

    @ApiOperation(value = "用户登陆")
    @PostMapping("/login")
    public ResultApi login(@ApiParam("用户登陆参数") @RequestBody AccountParam accountParam) {
        if (accountService.login(accountParam) != null) {
            return ResultApi.successDone(StateCode.SUCCESS);
        } else {
            return ResultApi.error(StateCode.FAIL, "用户名或密码错误");
        }
    }


    @ApiOperation(value = "用户注册")
    @PostMapping("/register")
    public ResultApi register(@ApiParam("用户注册参数")@RequestBody AccountParam accountParam) {
        if (accountService.register(accountParam) != 0) {
            return ResultApi.successDone(StateCode.SUCCESS);
        } else {
            return ResultApi.errorNotData(StateCode.FAIL);
        }
    }

}

